function posi = min_dis(filename, e, p)
%UNTITLED2 此处提供此函数的摘要
%   此处提供详细说明
path = 'TestDatabase\';

im = imread([path,filename]);%%%%读出测试图像
g=rgb2gray(im);

h=reshape(g,[200*180 1]);
L(:,1)=double(h);
pc=e'*L(:,1);%测试图像在特征空间中的投影
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for m=1:20
    d(m)=sum((pc(:,1)-p(:,m)).^2);%测试图像在特征空间中的投影与训练图像在特征空间中投影的距离
end
posi=find(d==min(d));%找距离最小的一个
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%把利用主成份分析在训练样本库中找到的与测试图距离最小的图像显示出来
f=['TrainDatabase\' num2str(posi) '.jpg'];
f1=imread(f);
result_image=rgb2gray(f1);
figure;
subplot(1,2,1)
imshow(g);
subplot(1,2,2)
imshow(result_image)
saveas(gca,['ks_pic\2.2_', filename])
end